package com.cakin.newssystem.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.service.ResponseMessage;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Licoy
 * @version 2018/4/18/10:54
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
public enum ResponseCode {
    /**
     * 操作成功枚举
     */
    OK(1, "操作成功"),
    /**
     * 登录成功枚举
     */
    SIGN_IN_OK(2, "登录成功"),
    /**
     * 注销成功枚举
     */
    LOGOUT_OK(3, "注销登录成功"),
    /**
     * 注册成功
     */
    REG_OK(4, "注册成功"),
    /**
     * 操作失败
     */
    FAIL(-1, "操作失败"),
    /**
     * 注销失败
     */
    LOGOUT_FAIL(-2, "注销登录失败"),

    /**
     * 登录失败
     */
    SIGN_IN_FAIL(-3, "登录失败"),
    /**
     * 账号或密码错误枚举
     */
    SIGN_IN_INPUT_FAIL(-4, "账号或密码错误"),
    /**
     * 账户和密码均不能为空
     */
    SING_IN_INPUT_EMPTY(-5, "账户和密码均不能为空"),
    /**
     * 用户未登录或身份异常
     */
    NOT_SING_IN(-6, "用户未登录或身份异常"),
    /**
     * 用户已注册
     */
    HAVE_REG(-7, "用户已注册"),
    /**
     * 用户已注册 TooManyResults
     */
    TOO_MANY_RESULTS(-8, "查询多条结果"),
    /**
     * 数据库操作异常
     */
    SQL_FAIL(-9, "SQL错误");
    /**
     * 错误码
     */
    private Integer code;
    /**
     * 错误消息
     */
    private String msg;

    public static List<ResponseMessage> getArrayMessage() {
        ArrayList<ResponseMessage> responseMessages = new ArrayList<>();
        for (ResponseCode statusEnum : ResponseCode.values()) {
            responseMessages.add(new ResponseMessageBuilder()
                    .code(statusEnum.code)
                    .message(statusEnum.msg)
                    .build());
        }
        return responseMessages;
    }
}
